
package com.yuke.cloud.service.uac.service.impl;

import com.yuke.cloud.common.base.constant.AliyunSmsConstants;
import com.yuke.cloud.common.base.constant.GlobalConstant;
import com.yuke.cloud.common.security.core.validate.code.sms.SmsCodeSender;
import com.yuke.cloud.service.uac.dto.SmsMessage;
import com.yuke.cloud.service.uac.service.SmsService;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;

/**
 * 默认的短信验证码发送器
 *
 * @author
 */
@Slf4j
public class UacSmsCodeSender implements SmsCodeSender {
	@Resource
	private SmsService smsService;

	@Override
	public void send(String mobile, String code, String ip, Integer validateType) {
		log.info("ip地址:{}向手机: {}:{}", ip, mobile, code);
		SmsMessage smsMessage = new SmsMessage();
		smsMessage.setMobileNo(mobile);
		smsMessage.setSmsCode(code);

		GlobalConstant.ValidateTypeEnum validateTypeEnum = GlobalConstant.ValidateTypeEnum.codeOf(validateType);
		if (validateTypeEnum != null) {
			AliyunSmsConstants.SmsTempletEnum smsTempletEnum = AliyunSmsConstants.SmsTempletEnum.getEnum(validateTypeEnum);
			smsMessage.setSmsTemplateCode(smsTempletEnum.getTempletCode());
		}else {
			smsMessage.setSmsTemplateCode(AliyunSmsConstants.SmsTempletEnum.UAC_SMS_IDENTITY_VER_TEMPLATE.getTempletCode());
		}

		smsService.sendSmsCode(smsMessage, ip);
	}

}
